//数塔
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long long C, N, temp, i, j, result;
    vector<vector <long long>> tower;
    vector<long long> slice;
    cin >> C;
    while (C--)
    {
        cin >> N;
        for (i = 1; i <= N; i++)
        {
            for (j = 1; j <= i; j++)
            {
                cin >> temp;
                slice.push_back(temp);
            }
            tower.push_back(slice);
            slice.clear();
        }
        for (i = N-2; i >= 0; i--)
        {
            for(j = 0; j<N-1; j++)
            {
                tower[i][j] += (tower[i + 1][j] > tower[i + 1][j + 1]
                                ? tower[i + 1][j] : tower[i + 1][j + 1]);
            }
        }
        cout << tower[0][0] << endl;
        tower.clear();
    }
}